package com.itheima.danli;
//懒汉式最终版本

public class SingleModel {

    //使用Volatile关键字修饰

    //不用Volatile修饰会发生指令重排序问题，导致单例模式失效
    private static volatile SingleModel singleModel;

    private SingleModel() {
    }

    public static SingleModel getInstance() {
        //DCL 双检和锁synchronized
        if (singleModel == null) {
            synchronized (SingleModel.class) {
                if (singleModel == null) {
                    singleModel = new SingleModel();
                }
            }
        }
        return singleModel;

    }
}
